package com.wj.console.common.taglib;

import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * @ClassName: PermissionTag
 * @Description: TODO
 * @author Administrator
 * @date 2016年6月13日 上午10:11:25
 *
 */
public class PermissionTag extends TagSupport {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -6230706522847825347L;

    // 模块中具体权限
    private String privilege;

    public String getPrivilege() {
        return privilege;
    }

    public void setPrivilege(String privilege) {
        this.privilege = privilege;
    }

    @Override
    public int doStartTag() throws JspException {
        boolean result = false;
        @SuppressWarnings("unchecked")
        Map<String, String> btnMap = (Map<String, String>) pageContext.getSession().getAttribute("roleMap");
        
        if (btnMap != null && btnMap.containsKey(privilege)) {
            result = true;
        }
        return result ? EVAL_BODY_INCLUDE : SKIP_BODY;// 真：返回EVAL_BODY_INCLUDE（执行标签）；假：返回SKIP_BODY（跳过标签不执行）
    }
}
